A Teen's Guide to C++ by Peter Le

A Teen's Guide to C++ by Peter Le

Author:Peter Le [Le, Peter]
Language: eng
Format: epub
Publisher: UNKNOWN
Published: 2018-11-18T23:00:00+00:00


6.6 Nested If, Else If, and Else Statements

A nested conditional is a conditional that is part of a conditional statement’s execution if it evaluates to true. You could also say it’s a conditional inside a conditional.

In other words, you can put a conditional INSIDE a conditional. WHOA! THAT’S COOL, AND YOU MAY NOT BE AS ENTHUSIASTIC AS I AM!

Group Exercise: Write a program to tell the user if an inputted number is between 40 and 50 (inclusive).

You might be thinking, didn’t I just do this program? Well here’s an alternative, longer way to do it.

Here’s the basic outline.

And here’s the nested conditional. Note that there are two else statements because if the number is greater than 40 and 50, it will not go to the original else statement, so you have to make a new one to catch that exception.

The program runs fine.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.